<!-- 市场结算 -->
<template>
    <div class="boxwrapper">
        <el-form :inline="true" :model="ruleForm" class="demo-form-inline">
            <el-form-item label="报表名称：">
                <el-input placeholder="请输入报表名称" v-model.trim="ruleForm.reportName" maxlength="20" size="small"></el-input>
            </el-form-item>

            <el-form-item>
                <el-button type="success"  @click="searchList"  id="monitorEnter" size="small">查询</el-button>
                <el-button type="primary"  @click="generateReport" size="small">生成报表</el-button>
            </el-form-item>
        </el-form>

        <el-table :data="tableData" border style="width: 100%">
            <el-table-column type="index" label="序号" width="50" align="center"></el-table-column>
            <el-table-column label="报表名称" prop="name" align="center"></el-table-column>
            <el-table-column label="月份" prop="month" align="center"></el-table-column>
            <el-table-column label="营收业绩（元）"  prop="totalAmount" align="center">
                <template slot-scope="scope">{{scope.row.totalAmount | initCash}}</template>
            </el-table-column>
            <el-table-column label="计提点数" prop="relList" align="center">
            	<template slot-scope="scope">
            		<el-button type="text" @click="initrelhander(scope.row)">查看</el-button>
            	</template>
            </el-table-column>
            <el-table-column label="市场分配明细（元）" prop="allotAmount" align="center">
                <template slot-scope="scope">
                    <span>{{scope.row.allotAmount | initCash}}</span>
                </template>
            </el-table-column>
            <el-table-column label="操作" align="center">
                <template slot-scope="scope"><el-button type="text" @click="seehander(scope.row)">查看详情</el-button></template>
            </el-table-column>
        </el-table>

        <div class="pagebar">
          <el-pagination
            background
            layout="total, sizes, prev, pager, next"
            :current-page.sync="ruleForm.pageNum"
            :page-sizes="[10, 20, 30, 40]"
            :page-size="ruleForm.pageSize"
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :total="totalSize">
          </el-pagination>
        </div>

        <el-dialog
        title=""
        :visible.sync="centerDialogVisible"
        width="50%"
        center>
            <div style="display: flex; justify-content:space-between;">
                <div style="width:45%">
                    <p>普通</p>
                    <el-table :data="tableData2" border style="width: 100%">
                       <el-table-column label="计提区间" prop="content" align="center"></el-table-column>
                   		<el-table-column label="计提比例%" width="100" prop="calculateExtractProportion" align="center">
                        </el-table-column>
                    </el-table>
                </div>
                <div style="width:45%">
                    <p>包销</p>
                    <el-table :data="tableData3" border style="width: 100%">
                        <el-table-column label="计提区间" prop="content" align="center"></el-table-column>
                            <el-table-column label="计提比例%" width="100" prop="calculateExtractProportion" align="center">
                         </el-table-column>
                    </el-table>
                 </div>
            </div>
            <span slot="footer" class="dialog-footer">
                <el-button type="primary" @click="centerDialogVisible = false">关闭</el-button>
            </span>
        </el-dialog>
    </div>
</template>
<script>
    import api from '@/api/apiPath'
    export default {
        name:'marketSettlement',
        title:'市场结算',
        data () {
            return {
                ruleForm:{
                    reportName:undefined,
                    pageNum: 0,
                    pageSize: 10,
                },
                ruleForm2:{
                    reportMonthId:undefined,
                    pageNum: 0,
                    pageSize: 10,
                },
                totalSize:0,
                totalSize2:0,
                centerDialogVisible:false,
                tableData:[],
                tableData2:[],
                tableData3:[],
            }
        },
        filters:{
            initCash(cellValue){
                if(cellValue !== 0 && cellValue){
                    return cellValue.toFixed(2).toString().replace(/\B(?=(\d{3})+(?!\d))/g,",");
                }
                if(cellValue == 0){
                    return "0.00"
                }
            },
        },
        methods:{
        	initrelhander(row){
        		 this.centerDialogVisible = true
                 this.getprofitdetail(row)
        	},
            getprofitdetail(val){
                this.axios.post(api.COMMALLOCATIONGETPROFITDETAIL+'Sort',{id:val.marketClearingStandardId}).then(res=>{
                    if (res.data.code == 200) {
                        this.tableData2 = res.data.data.ordinaryList
                        this.tableData3 = res.data.data.packageList
                    }
                })
            },
            handleCurrentChange(){
                this.getlist()
            },
            handleSizeChange(val){
                this.ruleForm.pageSize = val
                this.getlist();
            },
            getlist(){
                this.axios.post(api.COMMALLOCATIONGETMONTHLIST,this.ruleForm).then((res) => {
                  if (res && res.data.code == 200) {
                        this.tableData = res.data.data.data
                        this.totalSize = res.data.data.total
                   }
                })
            },
            generateReport(){
                this.$router.push({path:'/marketSettlementReport'})
            },
            searchList(){
                this.ruleForm.pageNum = 1
                this.getlist()
            },
            seehander(row){
                this.$router.push({path:'/marketSettlementDetail',query:{standardId: row.id,month:row.month}})
            }
        },
        activated(){
            this.searchList()
        },
        created(){
            this.getlist()
        }
    }
</script>

<style lang="stylus">

    .boxwrapper .el-table .cell {
         text-align: center;
         white-space: pre-line !important;
     }
</style>
